<?php

namespace Biz\service\Userpenalty;

use Doraemon\cache\Queue;
use Doraemon\cache\User as CacheUser;
use Doraemon\model\AdmOperateLog;
use Doraemon\model\AdmRecommendUser;
use Doraemon\model\AdmBestUser;
use Doraemon\model\Member;;


class Frozen
{
    public function handle( $data = [])
    {
        $uid = $data['uid'];
        if(empty($uid)) return false;
        $admin_id = $data['admin_id'];
        $admin_name = $data['admin_name'];
        //冻结用户的逻辑
        //删除用户在推荐表的数据
        AdmRecommendUser::deleteByUid($uid);
        //删除精华表数据
        AdmBestUser::deleteByUid($uid);
        //将用户的状态设置为冻结
        $member_data['status'] = Member::STATUS_FROZEN;
        $rst = Member::updateUserInfo($uid,$member_data);
        //删除token,强制退出登录
        Queue::insertQueue('User/frozen_user', array(
            'uid' => $uid,
        ), Queue::QUEUE_COMMON);
        Queue::insertQueue('User/delTokenCache', array(
            'uid' => $uid,
        ), Queue::QUEUE_COMMON);
        //删除cahce里面的缓存数据
        Queue::insertQueue('User/delUserinfoCache', array(
            'uid' => $uid,
        ), Queue::QUEUE_COMMON);
        if ($rst) {
            AdmOperateLog::addLog($uid,AdmOperateLog::$operate_type['frozen_user'],$admin_id,$admin_name);
            return true;
        } else {
            return false;
        }
    }

    public function cancle($data = [])
    {
        $uid = $data['uid'];
        if(empty($uid)) return false;
        $admin_id = $data['admin_id'];
        $admin_name = $data['admin_name'];
        $data['status'] = Member::STATUS_NORMAL;
        $rst = Member::updateUserInfo($uid,$data);
        if ($rst){
            $user_info = Member::getUserInfo($uid);
            $nick = $user_info['nick'];
            $mytype = $user_info['type'];
            Queue::insertQueue('User/addSearch', array(
                'uid' => $uid,
                'nick' => $nick,
                'type' => $mytype,
            ), Queue::QUEUE_COMMON);
            //删除cahce里面的缓存数据
            Queue::insertQueue('User/delUserinfoCache', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            AdmOperateLog::addLog($uid,AdmOperateLog::$operate_type['cancel_ban_user'],$admin_id,$admin_name);
            return true;
        }else{
            return false;
        }
    }

}